#!/usr/bin/python3
# -*- coding UTF-8 -*-
"""
生成器：
    生成器是一个用于创建迭代器的简单而强大的工具。
    返回数据时会使用 yield 语句，每次对生成器调用 next() 时，会从上次离开未知恢复执行
"""


def reverse(data):
    for index in range(len(data) - 1, -1, -1):
        yield data[index]


for char in reverse('golf'):
    print(char)

"""
生成器表达式
"""
print(sum(i * i for i in range(10)))
xvec = [10, 20, 30]
yvec = [7, 5, 3]
print(sum(x * y for x, y in zip(xvec, yvec)))
from math import pi, sin

sine_table = {x: sin(x * pi / 180) for x in range(0, 91)}
print(sine_table)
# unique_words = set(word for line in page for word in line.split())
# print(unique_words)
valedictorian = max((student.gpa, student.name) for student in graduates)
print(valedictorian)
data = 'golf'
print(list(data[i] for i in range(len(data) - 1, -1, -1)))
